// pages/register/register.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:"",
    age:0,
    locationName:"",
    locationAddress:"",
    phoneNum:"",
    latitude:"",
    longitude:"",
    sex:""
  },
  //获取地址
  getLoction(){
    wx.chooseLocation({
      // type:"gcj02",
      success:(res=>{
        console.log(res)
        this.setData({
          locationName:res.name,
          locationAddress:res.address,
          latitude:res.latitude,
          longitude:res.longitude
        })
      }),
      fail:(err=>{
        console.log(err)
      })
    })
  },
  //获取男女
  getSex(e){
    // console.log(e)
    var sex=""
    if(e.detail.value == "r1"){
      sex = "1"
    }else{
      sex = "0"
    }
    this.setData({
      sex:sex
    })
  },
  exit: function() {
    this.setData({
        dialog: false
    });
    wx.navigateBack({
      delta: 1,
    })
  },
  yes() {
    this.setData({
        dialog: false
    });
  },
  submitInfo(e){
    
    this.setData({
      phoneNum:e.detail.value.phoneNum,
      name:e.detail.value.name,
      age:e.detail.value.age
    })

    wx.request({
      url: app.globalData.Baseip+':8880/user/joinVolunteer',
      data:{
        "trueName":this.data.name,
        "sex":this.data.sex,
        "age":this.data.age,
        "address":this.data.locationName,
        "phone":this.data.phoneNum,
        "latitude":this.data.latitude,
        "longitude":this.data.longitude
      },
      method:'POST',
      header: {
       Authorization:app.globalData.header
      },
      success:function(res){
        console.log(res)
        wx.navigateBack({
          delta: 1,
        })
      },
      fail:function(err){
        console.log(err)
      }
    })


      


  },
  reset(){
    this.setData({
      name:"",
      age:0,
      locationName:"",
      locationAddress:"",
      phoneNum:"", 
      latitude:"",
      longitude:"",
      sex:"",

    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})